/**
 *
 */
import Util;
import OpenApi;
import OpenApiUtil;
import EndpointUtil;

extends OpenApi;


init(config: OpenApi.Config){
  super(config);
  @endpointRule = '';
  
  checkConfig(config);
  @endpoint = getEndpoint('mobi', @regionId, @endpointRule, @network, @suffix, @endpointMap, @endpoint);
}

function getEndpoint(productId: string, regionId: string, endpointRule: string, network: string, suffix: string, endpointMap: map[string]string, endpoint: string) throws: string{
  if (!Util.empty(endpoint)) {
    return endpoint;
  }
  
  if (!Util.isUnset(endpointMap) && !Util.empty(endpointMap[regionId])) {
    return endpointMap[regionId];
  }
  return EndpointUtil.getEndpointRules(productId, regionId, endpointRule, network, suffix);
}

model CreateAppFromTemplateRequest {
  actualParameters?: string(name='ActualParameters', example='[{"type":"bailianapp","name":"rag","actualParameter":"11"}]'),
  connectionsContent?: string(name='ConnectionsContent'),
  databasesContent?: string(name='DatabasesContent'),
  description?: string(name='Description'),
  from?: string(name='From'),
  icon?: string(name='Icon', description='This parameter is required.', example='-1'),
  name?: string(name='Name', description='This parameter is required.'),
  templateId?: string(name='TemplateId', description='This parameter is required.', example='4c892729-9950-4353-8146-33542b869e01'),
  type?: string(name='Type', example='Web'),
  variablesContent?: string(name='VariablesContent'),
  workspaceId?: string(name='WorkspaceId', description='This parameter is required.', example='1731664463*****'),
}

model CreateAppFromTemplateResponseBody = {
  data?: {
    appId?: string(name='AppId', example='172050620*****'),
    description?: string(name='Description'),
    gmtCreate?: string(name='GmtCreate', example='2024-03-26T10:22Z'),
    gmtModified?: string(name='GmtModified', example='2024-03-26T10:22Z'),
    icon?: string(name='Icon', example='-1'),
    name?: string(name='Name'),
    workspaceId?: string(name='WorkspaceId', example='1731664463*****'),
  }(name='Data'),
  requestId?: string(name='RequestId', description='Id of the request', example='36F552F7-E61E-556A-9957-8284318D1B9C'),
}

model CreateAppFromTemplateResponse = {
  headers?: map[string]string(name='headers'),
  statusCode?: int32(name='statusCode'),
  body?: CreateAppFromTemplateResponseBody(name='body'),
}

/**
 * @summary 通过模板创建应用
 *
 * @param request CreateAppFromTemplateRequest
 * @param runtime runtime options for this request RuntimeOptions
 * @return CreateAppFromTemplateResponse
 */
async function createAppFromTemplateWithOptions(request: CreateAppFromTemplateRequest, runtime: Util.RuntimeOptions): CreateAppFromTemplateResponse {
  Util.validateModel(request);
  var query = {};
  if (!Util.isUnset(request.actualParameters)) {
    query['ActualParameters'] = request.actualParameters;
  }
  if (!Util.isUnset(request.connectionsContent)) {
    query['ConnectionsContent'] = request.connectionsContent;
  }
  if (!Util.isUnset(request.databasesContent)) {
    query['DatabasesContent'] = request.databasesContent;
  }
  if (!Util.isUnset(request.description)) {
    query['Description'] = request.description;
  }
  if (!Util.isUnset(request.from)) {
    query['From'] = request.from;
  }
  if (!Util.isUnset(request.icon)) {
    query['Icon'] = request.icon;
  }
  if (!Util.isUnset(request.name)) {
    query['Name'] = request.name;
  }
  if (!Util.isUnset(request.templateId)) {
    query['TemplateId'] = request.templateId;
  }
  if (!Util.isUnset(request.type)) {
    query['Type'] = request.type;
  }
  if (!Util.isUnset(request.variablesContent)) {
    query['VariablesContent'] = request.variablesContent;
  }
  if (!Util.isUnset(request.workspaceId)) {
    query['WorkspaceId'] = request.workspaceId;
  }
  var req = new OpenApi.OpenApiRequest{ 
    query = OpenApiUtil.query(query),
  };
  var params = new OpenApi.Params{
    action = 'CreateAppFromTemplate',
    version = '2024-04-11',
    protocol = 'HTTPS',
    pathname = '/',
    method = 'POST',
    authType = 'AK',
    style = 'RPC',
    reqBodyType = 'formData',
    bodyType = 'json',
  };
  if (Util.isUnset(@signatureVersion) || !Util.equalString(@signatureVersion, 'v4')) {
    return callApi(params, req, runtime);
  } else {
    return execute(params, req, runtime);
  }
}

/**
 * @summary 通过模板创建应用
 *
 * @param request CreateAppFromTemplateRequest
 * @return CreateAppFromTemplateResponse
 */
async function createAppFromTemplate(request: CreateAppFromTemplateRequest): CreateAppFromTemplateResponse {
  var runtime = new Util.RuntimeOptions{};
  return createAppFromTemplateWithOptions(request, runtime);
}

